<?php

	$id = $_GET['id'];

	//ajax发送删除确认请求
	if(!empty($_SERVER['HTTP_X_REQUESTED_WITH'])){
		//先查询是否有子级？
		$sql = "select * from `cate` where pid=$id";
		$result = mysqli_query($link,$sql);
		echo ($result->num_rows>0)?1:0;
		die;

	}
	$row = getCateDel($id);

	if($row>0){
				echo '<script>alert("分类删除成功");location.href="index.php?c=cate&a=list&admin=1";</script>';die;
	              
		}else{
			echo '<script>alert("分类删除失败失败");history.go(-1);</script>';die;
		}

	

	//循环逐一地去查询每个分类下是否还有子集
	function getCateDel($pid=0){

		$sql = "select * from `cate` where pid=$pid ";
		$result = mysqli_query($GLOBALS['link'],$sql);
		//说明有子集
		if($result->num_rows>0){
			while($arr = mysqli_fetch_assoc($result)){

				//再去查询他的自己，然后调用自己
				getCateDel($arr['id']);
			}
		}

		del($GLOBALS['C'],$pid);
	}
	
	